/* eslint-disable guard-for-in */
/* eslint-disable no-restricted-syntax */
/* eslint-disable @typescript-eslint/no-explicit-any */
const camel2snake = (data: any): any => {
  if (typeof data !== 'object' || !data) {
    return data;
  }
  if (Array.isArray(data)) {
    return data.map((item) => camel2snake(item));
  }
  const newData: any = {};
  for (const key in data) {
    const newKey = key.replace(/([A-Z])/g, (p, m) => `_${m.toLowerCase()}`);
    newData[newKey] = camel2snake(data[key]);
  }
  return newData;
};
export default camel2snake;
